package com.ilarele.shopping.client.provider;

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.BaseColumns;

public class ShoppingListItemDB implements Parcelable, BaseColumns {

	public static final Uri CONTENT_URI = Uri
			.parse("content://shopping/list_items");

	public static final String GENERIC_ID = "generic_id";
	public static final String STATUS = "status";
	// public static final String GPS

	public static final String DEFAULT_SORT_ORDER = null;

	public String genericId;
	public int status;

	public ShoppingListItemDB() {
	}

	private ShoppingListItemDB(Parcel in) {
		genericId = in.readString();
		status = in.readInt();
	}

	public ContentValues getContentValues() {
		final ContentValues values = new ContentValues();
		values.put(GENERIC_ID, genericId);
		values.put(STATUS, status);
		return values;
	}

	public static ShoppingListItemDB fromCursor(Cursor c) {
		final ShoppingListItemDB item = new ShoppingListItemDB();

		item.genericId = c.getString(c.getColumnIndexOrThrow(GENERIC_ID));
		item.status = c.getInt(c.getColumnIndexOrThrow(STATUS));

		return item;
	}

	public int describeContents() {
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(genericId);
		dest.writeInt(status);
	}

	public static final Creator<ShoppingListItemDB> CREATOR = new Creator<ShoppingListItemDB>() {
		public ShoppingListItemDB createFromParcel(Parcel in) {
			return new ShoppingListItemDB(in);
		}

		public ShoppingListItemDB[] newArray(int size) {
			return new ShoppingListItemDB[size];
		}
	};
}
